export const loadPromise = (url = '') => {
	return new Promise((resolve, reject) => {
		if (!url) {
			resolve(true)
		}
		const img = new Image()
		img.src = url
		if (img.complete) { // 兼容性
			resolve(true)
		}
		img.onload = function () {
			resolve(true)
		}
	})
}

const imageAllPromise = (arr = []) => {
	return new Promise((resolve, reject) => {
		const resloveAll = []
		arr.forEach(item => {
			resloveAll.push(loadPromise(item))
		})
		window.Promise.all(resloveAll).then(res => {
			if (res) {
				resolve(true)
			}
		})
	})
}

export default imageAllPromise
